#include "pch.h"

#include "helper/cmdlineargs.h"



namespace Helper
{

	///
	CmdLineArgs::CmdLineArgs(const Helper::String &cmd):
m_cmdLine(cmd)
{
	this->Parse();
}




///
void CmdLineArgs::Parse()
{
	Array<String> tokens;

	this->m_cmdLine.Tokenize(" \t\n=", '"', tokens);

	if(1 != (tokens.Size() & 1))
	{
	}
	else
	{
		this->m_cmdLine = tokens[0];

		int num = tokens.Size() - 1;

		for(int i = 1; i < num; i += 2)
		{
			this->m_argNames.Add(tokens[i]);

			this->m_argValues.Add(tokens[i + 1]);
		}
	}
}



///
const String & CmdLineArgs::GetCmdLine() const
{
	return this->m_cmdLine;
}


///
const String & CmdLineArgs::GetCmdName() const 
{
	return this->m_cmdName;
}


///
bool CmdLineArgs::HasArg(const Helper::String &arg) const
{
	return (-1 != this->m_argNames.FindIndex(arg));
}


///
int CmdLineArgs::FindArgIndex(const Helper::String &arg) const
{
	return this->m_argNames.FindIndex(arg);
}


///
String CmdLineArgs::GetString(const Helper::String &name) const
{
	return this->m_argValues[this->FindArgIndex(name)];
}


///
int CmdLineArgs::GetInt(const Helper::String &name) const
{
	return this->m_argValues[this->FindArgIndex(name)].GetAsInt();
}


///
float CmdLineArgs::GetFloat(const Helper::String &name) const
{
	return this->m_argValues[this->FindArgIndex(name)].GetAsFloat();
}


///
bool CmdLineArgs::GetBool(const Helper::String &name) const
{
	return this->m_argValues[this->FindArgIndex(name)].GetAsBool();
}


///
Math::matrix CmdLineArgs::GetMatrix(const Helper::String &name) const
{
	return this->m_argValues[this->FindArgIndex(name)].GetAsMatrix();
}

}